home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.table;
-
- import com.sun.java.swing.JComponent;
- import com.sun.java.swing.JLabel;
- import com.sun.java.swing.JTable;
- import com.sun.java.swing.UIManager;
- import com.sun.java.swing.border.Border;
- import com.sun.java.swing.border.EmptyBorder;
- import java.awt.Color;
- import java.awt.Component;
- import java.io.Serializable;
-
- public class DefaultTableCellRenderer extends JLabel implements TableCellRenderer, Serializable {
- protected static Border noFocusBorder;
- private Color unselectedForeground;
- private Color unselectedBackground;
-
- public DefaultTableCellRenderer() {
- noFocusBorder = new EmptyBorder(1, 2, 1, 2);
- ((JComponent)this).setOpaque(true);
- ((JComponent)this).setBorder(noFocusBorder);
- }
-
- public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
- if (isSelected) {
- super.setForeground(table.getSelectionForeground());
- super.setBackground(table.getSelectionBackground());
- } else {
- super.setForeground(this.unselectedForeground != null ? this.unselectedForeground : ((Component)table).getForeground());
- super.setBackground(this.unselectedBackground != null ? this.unselectedBackground : ((Component)table).getBackground());
- }
-
- ((JLabel)this).setFont(((Component)table).getFont());
- if (hasFocus) {
- ((JComponent)this).setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
- if (table.isCellEditable(row, column)) {
- super.setForeground(UIManager.getColor("Table.focusCellForeground"));
- super.setBackground(UIManager.getColor("Table.focusCellBackground"));
- }
- } else {
- ((JComponent)this).setBorder(noFocusBorder);
- }
-
- this.setValue(value);
- return this;
- }
-
- public void setBackground(Color c) {
- super.setBackground(c);
- this.unselectedBackground = c;
- }
-
- public void setForeground(Color c) {
- super.setForeground(c);
- this.unselectedForeground = c;
- }
-
- protected void setValue(Object value) {
- ((JLabel)this).setText(value == null ? "" : value.toString());
- }
-
- public void updateUI() {
- super.updateUI();
- this.setForeground((Color)null);
- this.setBackground((Color)null);
- }
- }
-